<?php
namespace Admin\Controller;

use Think\Controller;
use Common\Model\NavigationModel;
use Admin\Controller\CommonController;
/**
 * 前台导航菜单 管理控制器
 */
class MenuController extends CommonController
{
    /*
    * 管理首页
    */
    public function index()
    {
        $model = new NavigationModel();
        $data = $model->getList();
        $url = U("admin/menu/index");
        $page = PageShow($data['count'],$url);
        $this->assign('data',$data)->assign('page',$page);
        $this->display();
    }

    /**
     * 添加菜单
     */
    public function add()
    {
        $model = new NavigationModel();
        if (IS_POST) {
            if (!$model->addNav()) {
                $this->error($model->getError());
                return false;
            }
            $this->success('添加成功',U("admin/menu/index"));
        }
        $menu = $model->getMenuList();
        $this->assign('menuList', $menu);
        $this->display();
    }

    /**
     * 修改菜单
     */
    public function edit()
    {
        $model = new NavigationModel();
        if (IS_POST) {
            if (!$model->editNav()) {
                $this->error($model->getError());
                return false;
            }
            $this->success('修改成功',U("admin/menu/index"));
        }
        $data = $model->find(I('id'));

        $this->assign('data', $data);
        $menu = $model->getMenuList();
        $this->assign('menuList', $menu);
        $this->display();
    }

    public function del(){
        $model = new NavigationModel();
        $model->delete(I("id"));
        $this->success('删除成功');
    }
}
